{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Flip Game"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: generatePossibleNextMoves"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #翻转游戏"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>你和朋友玩一个叫做「翻转游戏」的游戏。游戏规则如下：</p>\n",
    "\n",
    "<p>给你一个字符串 <code>currentState</code> ，其中只含 <code>'+'</code> 和 <code>'-'</code> 。你和朋友轮流将 <strong>连续 </strong>的两个 <code>\"++\"</code> 反转成 <code>\"--\"</code> 。当一方无法进行有效的翻转时便意味着游戏结束，则另一方获胜。</p>\n",
    "\n",
    "<p>计算并返回 <strong>一次有效操作</strong> 后，字符串 <code>currentState</code> 所有的可能状态，返回结果可以按 <strong>任意顺序</strong> 排列。如果不存在可能的有效操作，请返回一个空列表 <code>[]</code> 。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>currentState = \"++++\"\n",
    "<strong>输出：</strong>[\"--++\",\"+--+\",\"++--\"]\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>currentState = \"+\"\n",
    "<strong>输出：</strong>[]\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 <= currentState.length <= 500</code></li>\n",
    "\t<li><code>currentState[i]</code> 不是 <code>'+'</code> 就是 <code>'-'</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [flip-game](https://leetcode.cn/problems/flip-game/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [flip-game](https://leetcode.cn/problems/flip-game/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"++++\"', '\"+\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "\n",
    "\n",
    "        res = []\n",
    "        n = len(currentState)\n",
    "\n",
    "        for i in range(n):\n",
    "            if currentState[i] == \"+\" and i+1<n and currentState[i+1] == \"+\":\n",
    "                newState = currentState[:i]+\"--\"+currentState[i+2:]\n",
    "                res.append(newState)\n",
    "        \n",
    "        return res\n",
    "\n",
    "\n",
    "    def canWin(self, currentState: str) -> bool:\n",
    "\n",
    "\n",
    "        states = dict()\n",
    "\n",
    "\n",
    "        def play(player,currentState):\n",
    "            nextMove = self.generatePossibleNextMoves(currentState)\n",
    "\n",
    "            if nextMove == []:\n",
    "                \n",
    "                return player == 1\n",
    "\n",
    "            \n",
    "            for move in nextMove:\n",
    "                nextPlayer = (player+1)%2\n",
    "\n",
    "                if nextPlayer == 0:\n",
    "                    if not play(nextPlayer, move):\n",
    "                        return False\n",
    "                if nextPlayer == 1:\n",
    "                    if play(nextPlayer, move):\n",
    "                        return True\n",
    "               \n",
    "                    \n",
    "\n",
    "                   \n",
    "            return not nextPlayer\n",
    "        \n",
    "\n",
    "        res = play(0,currentState)\n",
    "\n",
    "        return res\n",
    "                        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "\n",
    "\n",
    "        res = []\n",
    "        n = len(currentState)\n",
    "\n",
    "        for i in range(n):\n",
    "            if currentState[i] == \"+\" and i+1<n and currentState[i+1] == \"+\":\n",
    "                newState = currentState[:i]+\"--\"+currentState[i+2:]\n",
    "                res.append(newState)\n",
    "        \n",
    "        return res\n",
    "\n",
    "\n",
    "    def canWin(self, currentState: str) -> bool:\n",
    "\n",
    "\n",
    "        states = dict()\n",
    "\n",
    "\n",
    "        def play(player,currentState):\n",
    "            nextMove = self.generatePossibleNextMoves(currentState)\n",
    "\n",
    "            if nextMove == []:\n",
    "                \n",
    "                return player == 1\n",
    "\n",
    "\n",
    "            if(player,currentState) in states:\n",
    "                return False\n",
    "            \n",
    "            for move in nextMove:\n",
    "                nextPlayer = (player+1)%2\n",
    "\n",
    "                if nextPlayer == 0:\n",
    "                    if not play(nextPlayer, move):\n",
    "                        states[(player,currentState)] = False\n",
    "                        return False\n",
    "\n",
    "                # if player 0 makes this move, and win, then win\n",
    "                if nextPlayer == 1:\n",
    "                    if play(nextPlayer, move):\n",
    "                        return True\n",
    "               \n",
    "            res = not nextPlayer\n",
    "            if not res:\n",
    "                states[(player,currentState)] = False\n",
    "            return res\n",
    "\n",
    "        \n",
    "\n",
    "        res = play(0,currentState)\n",
    "\n",
    "        return res\n",
    "                        \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, s: str) -> List[str]:\n",
    "        valid_moves: List[str] = []\n",
    "            \n",
    "        state: List[str] = list(s)\n",
    "        for i in range(1, len(state)):\n",
    "            if state[i - 1] == \"+\" and state[i] == \"+\":\n",
    "                state[i - 1] = \"-\"\n",
    "                state[i] = \"-\"\n",
    "                valid_moves.append(\"\".join(state))\n",
    "                state[i - 1] = \"+\"\n",
    "                state[i] = \"+\"\n",
    "            \n",
    "        return valid_moves"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        res = []\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                res.append(currentState[:i] + '--' + currentState[i+2:])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ans = []\n",
    "        n = len(currentState)\n",
    "        for i in range(1, n):\n",
    "            if currentState[i] == '+' and currentState[i-1] == '+':\n",
    "                ans.append(currentState[:i-1] + '--' + currentState[i+1:])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, s: str) -> List[str]:\n",
    "        ans=[]\n",
    "        k=len(s)\n",
    "        for j,x,y in zip(range(k),s,s[1:]):\n",
    "            if x==\"-\" or y==\"-\":continue\n",
    "            t=s[:j]+\"--\"+s[j+2:]\n",
    "            ans.append(t)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, CS: str) -> List[str]:\n",
    "        return [CS[:i]+\"--\"+CS[i+2:] for i in range(len(CS)) if CS.startswith(\"++\", i)]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ans = []\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i: i + 2] == \"++\":\n",
    "                ans.append(currentState[:i] + \"--\" + currentState[i + 2:])\n",
    "\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        \n",
    "        if len(currentState) < 2:\n",
    "            return []\n",
    "\n",
    "        res = []\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i] == currentState[i+1] == \"+\":\n",
    "                if i+2 < len(currentState):\n",
    "                    res.append(currentState[:i]+\"--\"+currentState[i+2:])\n",
    "                else:\n",
    "                    res.append(currentState[:i]+\"--\")\n",
    "            #elif currentState[i] == currentState[i+1] == \"-\":\n",
    "            #    if i+2 < len(currentState):\n",
    "            #        res.append(currentState[:i]+\"++\"+currentState[i+2:])\n",
    "            #    else:\n",
    "            #        res.append(currentState[:i]+\"++\")\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        res = []\n",
    "\n",
    "        if len(currentState) == 1:\n",
    "            return res\n",
    "        lie = list(currentState)\n",
    "        for i in range(1,len(lie)):\n",
    "            if lie[i] == '+' and lie[i-1] == '+':\n",
    "                lie[i] = '-'\n",
    "                lie[i-1] = '-'\n",
    "                res.append(''.join(lie))\n",
    "                lie[i] = '+'\n",
    "                lie[i-1] = '+'\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "\n",
    "\n",
    "        res = []\n",
    "        n = len(currentState)\n",
    "\n",
    "        for i in range(n):\n",
    "            if currentState[i] == \"+\" and i+1<n and currentState[i+1] == \"+\":\n",
    "                newState = currentState[:i]+\"--\"+currentState[i+2:]\n",
    "                res.append(newState)\n",
    "        \n",
    "        return res\n",
    "\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, s: str) -> List[str]:\n",
    "        ans=[]\n",
    "        k=len(s)\n",
    "        for j,x,y in zip(range(k),s,s[1:]):\n",
    "            if x==\"-\" or y==\"-\":continue\n",
    "            t=s[:j]+\"--\"+s[j+2:]\n",
    "            ans.append(t)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        result = []\n",
    "        for i in range(len(currentState)-1):\n",
    "            #为了不改变原来在遍历的currentState\n",
    "            # tmp = currentState \n",
    "            # if tmp[i] == '-':  字符串不可变\n",
    "            #     continue\n",
    "            # if tmp[i] == tmp[i+1]:\n",
    "            #     tmp[i] = '-'\n",
    "            #     tmp[i+1] = '-'\n",
    "            #     result.append(tmp)\n",
    "            # return result\n",
    "                \n",
    "            tmp = list(currentState)\n",
    "            if tmp[i] == '-':\n",
    "                continue\n",
    "            if tmp[i] == tmp[i+1]:\n",
    "                tmp[i] = '-'\n",
    "                tmp[i+1] = '-'\n",
    "                result.append(''.join(tmp))\n",
    "        return result\n",
    "                \n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ret=[]\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i:i+2]=='++':\n",
    "                ret.append(currentState[:i]+'--'+currentState[i+2:])\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ret_list = []\n",
    "        for idx in range(len(currentState) - 1):\n",
    "            if currentState[idx: idx + 2] == '++':\n",
    "                temp = list(currentState)\n",
    "                temp[idx] = '-'\n",
    "                temp[idx + 1] = '-'\n",
    "                ret_list.append(''.join(temp))\n",
    "        return ret_list \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        n=len(currentState)\n",
    "        ss=list(currentState)\n",
    "        res=[]\n",
    "        for i in range(1,n):\n",
    "            if ss[i]==\"+\" and ss[i-1]==\"+\":\n",
    "                ss[i]=\"-\"\n",
    "                ss[i-1]=\"-\"\n",
    "                # print(ss)\n",
    "                res.append(''.join(ss))\n",
    "                # print(res)\n",
    "\n",
    "                ss[i]=\"+\"\n",
    "                ss[i-1]=\"+\"\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        move_list = []\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                move_list.append(currentState[0:i]+\"--\"+currentState[i+2:])\n",
    "        return move_list\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        l = len(currentState)\n",
    "        move_list = []\n",
    "        for i, s1, s2 in zip(range(l), currentState, currentState[1:]):\n",
    "            if s1 != '+' or s2 != '+': continue\n",
    "            k = currentState[:i] + \"--\" + currentState[i + 2:]\n",
    "            move_list.append(k)\n",
    "        return move_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        data = currentState\n",
    "        re = []\n",
    "        for i in range(len(data) - 1):\n",
    "            if data[i: i + 2] == '++':\n",
    "                cur = data[:i] + '--' + data[i + 2:]\n",
    "                re.append(cur)\n",
    "        return re"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        res = []\n",
    "        if len(currentState) ==1:\n",
    "            return res\n",
    "\n",
    "        lie = list(currentState)\n",
    "        for i in range(1,len(lie)):\n",
    "            if lie[i] == '+'  and lie[i - 1] == '+':\n",
    "                lie[i] = '-'\n",
    "                lie[i - 1] = '-'\n",
    "                res.append(''.join(lie))\n",
    "                lie[i] = '+'\n",
    "                lie[i - 1] = '+'\n",
    "        \n",
    "\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        \n",
    "        if len(currentState) < 2:\n",
    "            return []\n",
    "\n",
    "        res = []\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i] == currentState[i+1] == \"+\":\n",
    "                if i+2 < len(currentState):\n",
    "                    res.append(currentState[:i]+\"--\"+currentState[i+2:])\n",
    "                else:\n",
    "                    res.append(currentState[:i]+\"--\")\n",
    "            #elif currentState[i] == currentState[i+1] == \"-\":\n",
    "            #    if i+2 < len(currentState):\n",
    "            #        res.append(currentState[:i]+\"++\"+currentState[i+2:])\n",
    "            #    else:\n",
    "            #        res.append(currentState[:i]+\"++\")\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        n = len(currentState)\n",
    "        lst = []\n",
    "        res = []\n",
    "        for i in range(n - 1):\n",
    "            j = i + 1 \n",
    "            if currentState[i] == '+' and currentState[j] == '+':\n",
    "                lst.append([i, j])\n",
    "        for val in lst:\n",
    "            x  = list(currentState)\n",
    "            x[int(val[0])] = '-'\n",
    "            x[int(val[1])] = '-'\n",
    "            res.append(''.join(x))\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        strs = []\n",
    "        str_t = ''\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i] =='+':\n",
    "                if currentState[i+1] =='+':\n",
    "                    str_t = list(currentState)\n",
    "                    str_t[i:i+2] = '--'\n",
    "                    strs.append(''.join(str_t))\n",
    "        return strs\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        res = []\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                res.append(currentState[:i] + '--' + currentState[i+2:])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        move_list = []\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                move_list.append(currentState[0:i]+\"--\"+currentState[i+2:])\n",
    "        return move_list\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ans=[]\n",
    "        for i in range(len(currentState)):\n",
    "            if currentState[i:i+2]=='++':\n",
    "                ans.append(currentState[0:i]+'--'+currentState[i+2:len(currentState)])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ret = []\n",
    "        n = len(currentState)\n",
    "        for i in range(1, n):\n",
    "            if currentState[i-1] == '+' and currentState[i] == '+':\n",
    "                ret.append(currentState[:i-1] + '--' + currentState[i+1:])\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        move_list = []\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                move_list.append(currentState[0:i]+\"--\"+currentState[i+2:])\n",
    "        return move_list\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        move_list = []\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                move_list.append(currentState[0:i]+\"--\"+currentState[i+2:])\n",
    "        return move_list\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        move_list = []\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i:i+2] == '++':\n",
    "                move_list.append(currentState[0:i]+\"--\"+currentState[i+2:])\n",
    "        return move_list\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, s: str) -> List[str]:\n",
    "        ans=[]\n",
    "        k=len(s)\n",
    "        for j,x,y in zip(range(k),s,s[1:]):\n",
    "            if x==\"-\" or y==\"-\":continue\n",
    "            t=s[:j]+\"--\"+s[j+2:]\n",
    "            ans.append(t)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        tmp1 = '++'\n",
    "        tmp2 = '--'\n",
    "        ans = []\n",
    "        for i in range(len(currentState)-1):\n",
    "            if currentState[i:i+2] == tmp1:\n",
    "                ans.append(currentState[:i]+tmp2+currentState[i+2:])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, s: str) -> List[str]:\n",
    "        ans=[]\n",
    "        for i in range(len(s)-1):\n",
    "            if s[i]==s[i+1]=='+':\n",
    "                ans.append(s[:i]+'--'+s[i+2:])\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, s: str) -> List[str]:\n",
    "        ans=[]\n",
    "        for i in range(len(s)-1):\n",
    "            if s[i]==s[i+1]=='+':\n",
    "                ans.append(s[:i]+'--'+s[i+2:])\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ls=list(currentState)\n",
    "        n=len(currentState)\n",
    "        ans=[]\n",
    "        for i in range(n-1):\n",
    "            if ls[i]==ls[i+1]==\"+\":\n",
    "                ls[i]=ls[i+1]=\"-\"\n",
    "                ans.append(\"\".join(ls))\n",
    "                ls[i]=ls[i+1]=\"+\"\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution(object):\n",
    "    def generatePossibleNextMoves(self, currentState):\n",
    "        store = [] \n",
    "        start_index = 0\n",
    "        while start_index < len(currentState)-1:\n",
    "            t2 = list(currentState)\n",
    "            u = \"\"\n",
    "            if currentState[start_index] == \"-\":\n",
    "                start_index += 1\n",
    "            elif currentState[start_index] == \"+\" and currentState[start_index+1] == \"+\":\n",
    "                t2.pop(start_index)\n",
    "                t2.insert(start_index,\"-\")\n",
    "                t2.pop(start_index+1)\n",
    "                t2.insert(start_index+1,\"-\")\n",
    "                store.append(\"\".join(t2))\n",
    "                start_index += 1\n",
    "            else:\n",
    "                start_index += 1\n",
    "        return store\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        tmp = \"++\"\n",
    "        tmp1 = \"--\"\n",
    "        res = []\n",
    "        for i in range(len(currentState)):\n",
    "            if currentState[i : i + 2] == tmp:\n",
    "                res.append(currentState[:i] + tmp1 + currentState[i + 2:])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        # 遍历一遍\n",
    "        tmp = \"++\"\n",
    "        tmp1 = \"--\"\n",
    "        result = []\n",
    "        for i in range(len(currentState)):\n",
    "            if currentState[i:i+2] == tmp:  # 遇到一个就生成一个答案\n",
    "                result.append(currentState[:i] + tmp1 + currentState[i+2:])\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        ret_list = []\n",
    "        state_list = list(currentState)\n",
    "        for idx in range(1, len(currentState)):\n",
    "            if state_list[idx] == '+' and state_list[idx - 1] == '+':\n",
    "                temp_list = state_list[:]\n",
    "                temp_list[idx] = '-'\n",
    "                temp_list[idx - 1] = '-'\n",
    "                ret_list.append(''.join(temp_list))\n",
    "        return ret_list\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def generatePossibleNextMoves(self, currentState: str) -> List[str]:\n",
    "        trans = {\"+\": \"-\", \"-\": \"+\"}\n",
    "        res = []\n",
    "        currentState_list = [i for i in currentState]\n",
    "        for i in range(len(currentState) - 1):\n",
    "            if currentState[i] == \"+\" and currentState[i + 1] == \"+\":\n",
    "                res.append(\"\".join(currentState_list[:i]) + trans[currentState[i]] * 2 + \"\".join(currentState_list[i+2:]))\n",
    "        return res"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
